package dbPhase.hypeerweb;

import org.junit.Test;
//import phase2Specification.testing.hypeerweb.ExpectedResult;

import junit.framework.TestCase;


// To use this class, comment out deletion code and comment in print statement in Node's removeFromHyPeerWeb() method
public class DeleteNodeTest  extends TestCase {

	public static HyPeerWeb hypeerweb = HyPeerWeb.getSingleton();
	@Test
	public void testAddNode() {
		hypeerweb.clear();
		boolean error = false;
		int errorCount = 0;

		Node node0 = new Node(0);
		hypeerweb.addToHyPeerWeb(node0, null);
		Node node1 = new Node(0);
		hypeerweb.addToHyPeerWeb(node1, node0);
		Node node2 = new Node(0);
		hypeerweb.addToHyPeerWeb(node2, node0);
		Node node3 = new Node(0);
		hypeerweb.addToHyPeerWeb(node3, node0);
		Node node4 = new Node(0);
		hypeerweb.addToHyPeerWeb(node4, node0);
		Node node5 = new Node(0);
		hypeerweb.addToHyPeerWeb(node5, node0);
		System.out.println("HyPeerWeb with 6 nodes. 0 - 5");
		System.out.println("Removing Node 0 .....");
		node0.removeFromHyPeerWeb();
		if (node0.neighbors.size() != 0) {
			System.out.println("Node 0: neighborssize Wrong: " + node0.neighbors.size());
			error = true;
			errorCount++;
			}
		if (node0.downPointers.size() != 0) {
			System.out.println("Node 0: downPointerssize Wrong: " + node0.downPointers.size());
			error = true;
			errorCount++;
			}
		if (node0.upPointers.size() != 0) {
			System.out.println("Node 0: upPointersize Wrong: " + node0.upPointers.size());
			error = true;
			errorCount++;
			}





//		if (node0.webId.getValue() != 0) {
//			System.err.println("Node 0: Webid Wrong: " + node0.webId.getValue()); error = true; errorCount++;}
//		if (node0.fold.webId.getValue() != 0) {
//			System.err.println("Node 0: Fold Wrong, should be 0: " + node0.fold.webId.getValue()); error = true; errorCount++;}
//		if (node0.neighbors.size() != 0) {
//			System.err.println("Node 0: neighborssize Wrong: " + node0.neighbors.size()); error = true; errorCount++;}
//		if (node0.downPointers.size() != 0) {
//			System.err.println("Node 0: downPointerssize Wrong: " + node0.downPointers.size()); error = true; errorCount++;}
//		if (node0.upPointers.size() != 0) {
//			System.err.println("Node 0: upPointersize Wrong: " + node0.upPointers.size()); error = true; errorCount++;}
//		if (node0.nodeState != HypercubeCapState.getSingleton()) {
//			System.err.println("Node 0: nodeState Wrong, should be Cap: " + node0.nodeState.toString()); error = true; errorCount++;}
//
//
//
//		System.err.println("Size is 1, add node1");
//
//		if (node0.webId.getValue() != 0) {
//			System.err.println("Node 0: Webid Wrong: " + node0.webId.getValue()); error = true; errorCount++;}
//		if (node0.fold.webId.getValue() != 1) {
//			System.err.println("Node 0: Fold Wrong, should be 1: " + node0.fold.webId.getValue()); error = true; errorCount++;}
//		if (node0.neighbors.size() != 1) {
//			System.err.println("Node 0: neighborssize Wrong: " + node0.neighbors.size()); error = true; errorCount++;}
//		if (node0.downPointers.size() != 0) {
//			System.err.println("Node 0: downPointerssize Wrong: " + node0.downPointers.size()); error = true; errorCount++;}
//		if (node0.upPointers.size() != 0) {
//			System.err.println("Node 0: upPointersize Wrong: " + node0.upPointers.size()); error = true; errorCount++;}
//		if (node0.nodeState != StandardNodeState.getSingleton()) {
//			System.err.println("Node 0: nodeState Wrong, should be Standard: " + node0.nodeState.toString()); error = true; errorCount++;}
//
//		if (node1.webId.getValue() != 1) {
//			System.err.println("Node 1: Webid Wrong: " + node1.webId.getValue()); error = true; errorCount++;}
//		if (node1.fold.webId.getValue() != 0) {
//			System.err.println("Node 1: Fold Wrong, should be 0: " + node1.fold.webId.getValue()); error = true; errorCount++;}
//		if (node1.neighbors.size() != 1) {
//			System.err.println("Node 1: neighborssize Wrong: " + node1.neighbors.size()); error = true; errorCount++;}
//		if (node1.downPointers.size() != 0) {
//			System.err.println("Node 1: downPointerssize Wrong: " + node1.downPointers.size()); error = true; errorCount++;}
//		if (node1.upPointers.size() != 0) {
//			System.err.println("Node 1: upPointersize Wrong: " + node1.upPointers.size()); error = true; errorCount++;}
//		if (node1.nodeState != HypercubeCapState.getSingleton()) {
//			System.err.println("Node 1: nodeState Wrong, should be Cap: " + node1.nodeState.toString()); error = true; errorCount++;}
//
//
//
//
//
//		if (node2.downPointers.size() != 1) {
//			System.err.println("Node 2: downPointers size Wrong, should be 1: " + node2.downPointers.size()); error = true; errorCount++;}
//
//		if (node0.nodeState != StandardNodeState.getSingleton()) {
//			System.err.println("Node 0: nodeState Wrong, should be standard: " + node0.nodeState.toString()); error = true; errorCount++;}
//		if (node1.nodeState != UpPointingNodeState.getSingleton()) {
//			System.err.println("Node 1: nodeState Wrong, should be UpPointingNodeState: " +
//								node1.nodeState.toString()); error = true; errorCount++;}
//		if (node2.nodeState != TerminalNodeState.getSingleton()) {
//			System.err.println("Node 1: nodeState Wrong, should be TerminalNodeState: " +
//								node2.nodeState.toString()); error = true; errorCount++;}


		assertFalse(error);
		assertFalse(errorCount < 0);
	}

//    private static void printErrorMessage(int size, Node startNode, SimplifiedNodeDomain simplifiedNodeDomain, ExpectedResult expectedResult) {
//	      errorCount++;
//
//        System.out.println("-------------------------------------------------------------");
//        System.out.println("INSERTION ERROR when HyPeerWebSize = " + size + ", Start Location: " + startNode);
//        System.out.println("Node Information:");
//        System.out.println(simplifiedNodeDomain);
//        System.out.println();
//        System.out.println("Expected Information");
//        System.out.println(expectedResult);
//    }
//
//	 static private void createHyPeerWebWith(int numberOfNodes) {
//	        hypeerweb.clear();
//	        Node node0 = new Node(0);
//	        hypeerweb.addToHyPeerWeb(node0, null);
//
//	        for (int i = 1; i < numberOfNodes; i++) {
//	            Node node = new Node(0);
//	            node0.addToHyPeerWeb(node);
//	        }
//	    }
}
